package com.sky.controller.admin;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.pojo.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @ApiOperation("分页查询套餐")
    @GetMapping("/page")
    public Result<PageResult> findByPage(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = setmealService.findByPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("新增套餐")
    @PostMapping
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.addSetmeal(setmealDTO);
        return Result.success("添加成功");
    }

    @ApiOperation("批量删除套餐")
    @DeleteMapping()
    public Result deleteBatch(@RequestParam List<Long> ids){
        setmealService.deleteBatch(ids);
        return Result.success("删除成功");
    }

    @ApiOperation("回显：根据id查询套餐数据")
    @GetMapping("/{id}")
    public Result findById(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.findById(id);
        return Result.success(setmealVO);
    }

    @ApiOperation("修改套餐")
    @PutMapping()
    public Result update(@RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return Result.success("修改成功");
    }

    @ApiOperation("起售停售")
    @PostMapping("status/{status}")
    public Result updateStatus(@PathVariable Integer status,@RequestParam Long id){
        setmealService.updateStatus(status,id);
        return Result.success("已修改");
    }


}
